#!/bin/bash
sudo dpkg --configure -a
sleep 1s
wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/KlipperScreen-requirements.txt  -O /home/print3D/KlipperScreen/scripts/KlipperScreen-requirements.txt &>/dev/null
sudo /home/print3D/klippy-env/bin/pip install -r "/home/print3D/klipper/scripts/klippy-requirements.txt" -i https://pypi.mirrors.ustc.edu.cn/simple/  
sudo /home/print3D/moonraker-env/bin/pip install -r "/home/print3D/moonraker/scripts/moonraker-requirements.txt" -i https://pypi.mirrors.ustc.edu.cn/simple/  
sudo /home/print3D/KlipperScreen-env/bin/pip install -r "/home/print3D/KlipperScreen/scripts/KlipperScreen-requirements.txt" -i https://pypi.mirrors.ustc.edu.cn/simple/  
sleep 1s
test -e /etc/init.d/kliqj
if [ $? -eq 0 ]; then
    echo  -e "====kliqj已安装!===="
else
   echo  -e "====重装kliqj!===="
   wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/kliqj_start.sh  -O /etc/init.d/kliqj &>/dev/null
fi
test -e /etc/init.d/klipper
if [ $? -eq 0 ]; then
    echo  -e "====klipper启动已安装!===="
else
   echo  -e "====重装klipper启动!===="
   wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/klipper-start.sh  -O /etc/init.d/klipper &>/dev/null
fi
test -e /etc/init.d/moonraker
if [ $? -eq 0 ]; then
    echo  -e "====moonraker启动已安装!===="
else
   echo  -e "====重装moonraker启动!===="
   wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/moonraker-start.sh  -O /etc/init.d/moonraker &>/dev/null
fi
test -e /etc/init.d/nginxk
if [ $? -eq 0 ]; then
    echo  -e "====nginxk启动已安装!===="
else
   echo  -e "====重装nginxk启动"
   wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/nginxk_start.sh  -O /etc/init.d/nginxk &>/dev/null
fi
test -e /etc/init.d/KlipperScreen
if [ $? -eq 0 ]; then
    echo  -e "====KlipperScreen启动已安装!===="
else
   echo  -e "====重装KlipperScreen启动!===="
   wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/KlipperScreen_start.sh  -O /etc/init.d/KlipperScreen &>/dev/null
fi
test -e /etc/init.d/KlipperScreensh
if [ $? -eq 0 ]; then
    echo  -e "====KlipperScreensh已安装!===="
else
   echo  -e "====重装KlipperScreensh!===="
   wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/KlipperScreen.sh  -O /etc/init.d/KlipperScreensh &>/dev/null
fi
test -e /root/print3D/ksdelay.sh
if [ $? -eq 0 ]; then
    echo  -e "====ksdelay.sh已安装!===="
else
   echo  -e "====重装ksdelay.sh!===="
   wget https://gitee.com/xiaoh5001/klipperocto4a/raw/master/scripts/ksdelay.sh  -O /root/print3D/ksdelay.sh &>/dev/null
fi
test -e /home/print3D/printer_data/config/KlipperScreen.conf
if [ $? -eq 0 ]; then
    echo  -e "====KlipperScreen.conf已安装!===="
else
   echo  -e "====重装KlipperScreen.conf!===="
   wget https://gitee.com/xiaoh5001/klipperocto4a/raw/master/scripts/KlipperScreen.conf  -O /home/print3D/printer_data/config/KlipperScreen.conf &>/dev/null
fi
test -e /home/print3D/printer_data/config/moonraker.conf
if [ $? -eq 0 ]; then
    echo  -e "====moonraker.conf已安装!===="
else
   echo  -e "====重装moonraker.conf!===="
   wget https://gitee.com/xiaoh5001/klipperocto4a/raw/master/scripts/moonraker.conf  -O /home/print3D/printer_data/config/moonraker.conf &>/dev/null
fi
test -e /home/print3D/printer_data/config/printer.cfg
if [ $? -eq 0 ]; then
    echo  -e "====printer.cfg已安装!===="
else
   echo  -e "====重装printer.cfg!===="
   wget https://gitee.com/xiaoh5001/klipperocto4a/raw/master/scripts/printer.cfg  -O /home/print3D/printer_data/config/printer.cfg &>/dev/null
fi
[[ -f  "/lib/$@/libc.so"  ]] && rm -rf "/lib/$@/libc.so"   
ln -s "/lib/$@/libc.so.6"  "/lib/$@/libc.so" 
if [ $? -eq 0 ]; then
            echo  -e "====创建libc.so链接成功!===="
else
        [[ -f  "/lib/$@/libc.so"  ]] && rm -rf "/lib/$@/libc.so"
        ln -s "/lib/$@/libc.so.6"  "/lib/$@/libc.so"  
        if [ $? -eq 0 ]; then
            echo  -e "====重新创建libc.so链接成功!===="
        else
            echo  -e "====创建libc.so链接失败!====" 
        fi
fi
sleep 1s
chmod +x -R /etc/init.d
chmod 777 -R /etc/init.d
chmod +x /root/print3D/ksdelay.sh
chmod 777 /root/print3D/ksdelay.sh